package com.czd.support.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.czd.base.model.Paginate;
import com.czd.base.service.BaseService;
import com.czd.support.common.Configuration;
import com.czd.support.model.Company;

 
/**
 * @Description  企业信息管理
 * @Author JinMa.Xiao
 * @Date    2015年6月18日 下午4:57:28
 * @Version v1.0
 */
@Service
public class CompanyService   extends  BaseService<Company> {
	

	public Paginate queryForPaginate(Company company, String kw) {
		company.setWhere(" 1=1");
        if(StringUtils.isNotBlank(kw)){
        	company.setWhere(company.getWhere() + " and (code like '"+kw+"%' or name like '"+kw+"%' or logoUrl like '"+kw+"%')");
        }
		company.setPageSize(Configuration.getInstance().getDefault_page_size());
		if (StringUtils.isNotBlank(kw)) {
			company.setWhere(company.getWhere() + " and (code like '" + kw
					+ "%' or name like '" + kw + "%' or logoUrl like '" + kw
					+ "%')");
		}
		return this.queryForPaginate(sqlId("queryForPage"), company);
	}

	public boolean insert(Company company) {
		return this.insert(sqlId("insert"), company);
	}
	
	public  Company findById(int  id){
		Company selectOne = this.selectOne("findById", id);
		return  selectOne;
		       
	}
	public  List<Company> findAll(){
		  
		return  this.selectList("findAll");
		
	}   
	
	 public boolean deleteById(int id){
	        return  this.delete(sqlId("deleteById"),id);
	    }
	 
	 public boolean update(Company company) {
			return this.update(sqlId("update"), company);
		}
	 
	 public boolean updateNav(int id) {
			return this.update(sqlId("updateNav"), id);
		}




	public List<Company> getAllCompanies(){
		return this.selectList(sqlId("getAllCompanies"));
	}
}
